<template>
  <div class="app-container">
    <el-row :gutter="20">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="任务名称" prop="taskName">
        <el-input
          v-model="queryParams.taskName"
          placeholder="请输入任务名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单名称" prop="workOrderName">
        <el-input
          v-model="queryParams.workOrderName"
          placeholder="请输入工单名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单状态" prop="workOrderStauts">
        <el-select v-model="queryParams.workOrderStauts" placeholder="请选择工单状态">
          <el-option
            v-for="dict in workOrderStautsS"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['zndd:solution:add']"
              >新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                plain
                icon="el-icon-edit"
                size="mini"
                :disabled="single"
                @click="handleUpdate"
                v-hasPermi="['zndd:solution:edit']"
              >修改</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                plain
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['zndd:solution:remove']"
              >删除</el-button>
            </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zndd:solution:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="znddList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" :index="indexMethod"></el-table-column>
      <el-table-column label="任务名称" align="center" width="180" prop="taskName" />
      <el-table-column label="工单名称" align="center" width="180" prop="workOrderName" show-overflow-tooltip/>
      <el-table-column label="工单号" align="center" width="180" prop="workOrderNo" show-overflow-tooltip/>
      <el-table-column label="工单状态" align="center" width="150" prop="workOrderStauts" :formatter="solutionFormatter"/>
      <el-table-column label="生产总车序" align="center" width="130" prop="ji" />
      <el-table-column label="任务车序" align="center" width="130" prop="carOrder" />
      <el-table-column label="工序顺序" align="center" width="130" prop="orderSequence" />
      <el-table-column label="解决方案" align="center" width="550" prop="solutionDescribe" :formatter="formatTime" show-overflow-tooltip/>
      <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip/>
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-edit"-->
      <!--            @click="handleUpdate(scope.row)"-->
      <!--            v-hasPermi="['zndd:solution:edit']"-->
      <!--          >修改</el-button>-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-delete"-->
      <!--            @click="handleDelete(scope.row)"-->
      <!--            v-hasPermi="['zndd:solution:remove']"-->
      <!--          >删除</el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList" />
    </el-row>

    <!-- 添加或修改解决方案信息对话框 -->
    <!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="部门id" prop="deptId">
              <el-input v-model="form.deptId" placeholder="请输入部门id" />
            </el-form-item>
            <el-form-item label="任务id" prop="taskId">
              <el-input v-model="form.taskId" placeholder="请输入任务id" />
            </el-form-item>
            <el-form-item label="工单id" prop="workOrderId">
              <el-input v-model="form.workOrderId" placeholder="请输入工单id" />
            </el-form-item>
            <el-form-item label="车辆顺序" prop="carOrder">
              <el-input v-model="form.carOrder" placeholder="请输入车辆顺序" />
            </el-form-item>
            <el-form-item label="解决方案说明" prop="solutionDescribe">
              <el-input v-model="form.solutionDescribe" type="textarea" placeholder="请输入内容" />
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>-->
  </div>
</template>

<script>
import { listZndd, getZndd, delZndd, addZndd, updateZndd } from "@/api/zndd/solution/solution";

export default {
  name: "solution",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //问题类型数据
      workOrderStautsS:[],
      // 解决方案信息表格数据
      znddList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskName: null,
        workOrderName: null,
        workOrderNo: null,
        workOrderStauts: null,
        carOrder: null,
        // solutionDescribe: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deptId: [
          { required: true, message: "部门id不能为空", trigger: "blur" }
        ],
        taskId: [
          { required: true, message: "任务id不能为空", trigger: "blur" }
        ],
        workOrderId: [
          { required: true, message: "工单id不能为空", trigger: "blur" }
        ],
        carOrder: [
          { required: true, message: "车辆顺序不能为空", trigger: "blur" }
        ],
        solutionDescribe: [
          { required: true, message: "解决方案说明不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    //获取字典表中产线类型
    this.getDicts("zndd_worker_order_status").then(response => {
      this.workOrderStautsS = response.data;
    });
    this.getList();
  },
  methods: {
    formatTime(row, column, cellValue) {
      if (cellValue.includes('加时间')) {
        const numberPattern = /\d+/g;
        const numbers = cellValue.match(numberPattern);
        if (numbers && numbers.length > 0) {
          const totalSeconds = parseInt(numbers[0], 10);
          let timeString = '';
          if (totalSeconds >= 3600){
            const hour = Math.floor(totalSeconds / 3600);
            const minutes = Math.floor(totalSeconds / 60) % 60;
            const seconds = Math.floor(totalSeconds % (3600 * hour) % 60);
            timeString = `${hour}小时${minutes}分${seconds}秒`;
          }else if (totalSeconds >= 60){
            const minutes = Math.floor(totalSeconds / 60);
            const seconds = Math.floor(totalSeconds % 60);
            timeString = `${minutes}分${seconds}秒`;
          }else {
            timeString = `${totalSeconds}秒`;
          }
          const beforeTimeString = cellValue.split('加时间')[0];
          const bt = beforeTimeString + '加时间';
          return `${bt}${timeString}`;
        }
      }
      return cellValue;
    },
    //格式化问题类型
    solutionFormatter(row, column) {
      const workOrderStatus = this.workOrderStautsS.find(workOrderStauts => workOrderStauts.dictValue === row.workOrderStauts);
      return workOrderStatus ? workOrderStatus.dictLabel : '';
    },
    /** 序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if (pageNum !== -1 && pageNum !== 0) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return index + 1;
      }
    },
    /** 查询解决方案信息列表 */
    getList() {
      this.loading = true;
      listZndd(this.queryParams).then(response => {
        this.znddList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        taskName: null,
        workOrderName: null,
        workOrderNo: null,
        workOrderStauts: null,
        solutionDescribe: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加解决方案信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getZndd(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改解决方案信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateZndd(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZndd(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除解决方案信息编号为"' + ids + '"的数据项？').then(function() {
        return delZndd(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zndd/zndd/export', {
        ...this.queryParams
      }, `zndd_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style lang="css" scoped>

/* 自定义滚动条样式 */
::v-deep ::-webkit-scrollbar {
  width: 12px; /* 水平滚动条的宽度 */
  height: 12px; /* 垂直滚动条的高度 */
  cursor: pointer; /* 鼠标靠近滚动条时变为小手样式 */
}

::v-deep ::-webkit-scrollbar-track {
  background: #f1f1f1; /* 滚动条轨道的颜色 */
  cursor: pointer; /* 鼠标靠近滚动条轨道时变为小手样式 */
}

::v-deep ::-webkit-scrollbar-thumb {
  background: #888; /* 滚动条滑块的颜色 */
  border-radius: 6px; /* 滚动条滑块的圆角 */
  cursor: pointer; /* 鼠标靠近滚动条滑块时变为小手样式 */
}

::v-deep ::-webkit-scrollbar-thumb:hover {
  background: #555; /* 滚动条滑块悬停时的颜色 */
  cursor: pointer; /* 鼠标悬停在滚动条滑块上时仍保持小手样式 */
}
</style>
